<!--
 * @Author: wangding
 * @Date: 2020-11-11 15:58:31
 * @LastEditTime: 2021-01-28 15:34:30
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\device\sale\add.vue
-->
<template>
    <div>
        <el-dialog
        :title="$t('devUpgrade.VersionToUp')"
        :visible="newVisibleEdit"
        class="el-dialog-sm"
        @close="()=>{$store.commit('setNewVisibleEdit',false)}"
        :close-on-click-modal='false'
        >   
            <el-row :gutter="20">
                <el-col :span="19" :offset="2">
                    <el-form ref="form" :model="form" label-width="150px" >
                        <el-form-item label="版本号" prop="packageId" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <el-select v-model="form.packageId" :placeholder="$t('pleaseSelect')" filterable  clearable>
                                <el-option
                                v-for="item in packageList"
                                :key="item.sid"
                                :label="item.fullVersion"
                                :value="item.sid">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setNewVisibleEdit',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    components: {
    },
    props: {
        packageList:Array,
        gatewayIds:''
    },
    data() {
        return {
            form:{
                packageId:'',
            },
        };
    },
    computed: {
        newVisibleEdit(){
            return this.$store.state.sysStore.newVisibleEdit
        }
    },
    watch: {

    },
    created() {

    },
    mounted() {

    },
    methods: {
        async updateUpdateVersion(){
            let res = await this.API.devgatewayDownMessage({
                packageId:this.form.packageId,
                gatewayIds:this.gatewayIds
            })
            if(res.success){
                this.comm.showMsg(res.success,this.$t('devUpgrade.waitForUpgrade'))
                this.$store.commit('setNewVisibleEdit',false)
                this.$emit('refreshStatus',this.gatewayIds)
            }else{
                this.comm.showMsg(res.success)
            }
        },
        save(formName){
            this.$refs[formName].validate((valid) => {
              if (valid) {
                  this.updateUpdateVersion()
              } else {
                console.log('error submit!!');
                return false;
              }
            });
        }
    },
};
</script>

<style  lang="less" >
</style>
